package com.flash.BusinessParameters.service.impl;

import com.flash.BusinessParameters.entity.Broker;

import com.flash.BusinessParameters.mapper.BrokerMapper;
import com.flash.BusinessParameters.service.BrokerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class BrokerServiceImpl implements BrokerService {

    @Resource
    BrokerMapper brokerMapper;

    /**
     * 查询全部
     * @return
     */
    @Override
    public List<Broker> selectBroker() {
        return brokerMapper.selectBroker();
    }

    /**
     * 增加
     * @param broker
     * @return
     */
    @Override
    public int insertBroker(Broker broker) {
        return brokerMapper.insertBroker(broker);
    }

    /**
     * 删除
     * @param brokerId
     * @return
     */
    @Override
    public int deleteBroker(String brokerId) {
        return brokerMapper.deleteBroker(brokerId);
    }

    /**
     * 修改
     * @param broker
     * @return
     */
    @Override
    public int updateBroker(Broker broker) {
        return brokerMapper.updateBroker(broker);
    }

    /**
     * 条件查询全部
     * @param brokerName
     * @param page
     * @param limit
     * @return
     */
    @Override
    public List<Broker> selectBrokerMap(String brokerName, int page, int limit) {
        HashMap map = new HashMap();
        map.put("brokerName" , buildWhere(brokerName));
        map.put("page",(page-1)*limit);
        map.put("limit",limit);
        return brokerMapper.selectBrokerMap(map);
    }

    /**
     * 分页
     * @return
     */
    @Override
    public int selectCountBroker() {
        return brokerMapper.selectCountBroker();
    }

    /**
     * 条件查询
     * @param brokerName
     * @return
     */
    public String buildWhere(String brokerName){
        StringBuffer strWhere=new StringBuffer();
        if(brokerName!=null && !brokerName.equals("")){
            strWhere.append(" and brokerName like '%" + brokerName + "%'" );
        }
        return strWhere.toString();
    }

}
